package hhh.app.presenter.model.cart;

import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import hhh.app.R;
import hhh.app.presenter.ui.base.BaseActivity;
import hhh.app.presenter.ui.view.RecyclerRefreshLayout;

/**
 * Created by Administrator on 2017/3/18 0018.
 */
public class CartActivity extends BaseActivity {
    @BindView(R.id.cart_img)
    ImageView cartImg;
    @BindView(R.id.cart_title)
    TextView cartTitle;
    @BindView(R.id.cart_toolbar)
    Toolbar cartToolbar;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.recyclerRefreshLayout)
    RecyclerRefreshLayout recyclerRefreshLayout;
    @BindView(R.id.cart_rb)
    RadioButton cartRb;
    @BindView(R.id.cart_account)
    Button cartAccount;

    List<String> mList;
    CommonAdapter<String> adapter;

    @Override
    protected void init() {
        mList=new ArrayList<String>();
        mList.add("init 1");

        recyclerRefreshLayout.setColorSchemeResources(R.color.primary,
                R.color.accent,
                R.color.orange,
                R.color.colorAccent);
        recyclerRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mList.add("handler 1");
                        adapter.notifyDataSetChanged();

                        recyclerRefreshLayout.setRefreshing(false);
                    }
                },1200);
            }
        });
        adapter=new CommonAdapter<String>(this,R.layout.layout_list_item3,mList) {
            @Override
            protected void convert(ViewHolder holder, String s, int position) {
                holder.setText(R.id.item3_title,s);
            }
        };
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setHasFixedSize(true);
        recyclerView.setAdapter(adapter);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_cart;
    }
}
